/*
 *
 * C++ MaJiang for 血流红中
 *
 * TuyooGame, 2021
 * zhouxin@tuyoogame.com
 *
 */
#include "xueliuhz/fan.h"

using namespace std;

//
//const map 不能用[]访问，需要用at方法
//例如：int8_t ret = fxFuncMap.at(SIANKE)(&cp_mfi);
//
const unordered_map<MJ_FANXING, MJ_FANXING_DETAIL> fanPattern {

    {SANLONGQIDUI, {"sanlongqidui", "三龙七对", 288}},
    {SHIBALUOHAN, {"shibaluohan", "十八罗汉", 128}},
    {YISESHUANGLONGHUI, {"yiseshuanglonghui", "一色双龙会", 128}},
    {QUANYAOJIU, {"quanyaojiu", "全幺九", 96}},
    {LIANQIDUI, {"lianqidui", "连七对", 96}},
    {SHUANGLONGQIDUI, {"shuanglongqidui", "双龙七对", 96}},
    {JIULIANBAODENG, {"jiulianbaodeng", "九莲宝灯", 64}},
    {SIANKE, {"sianke", "四暗刻", 32}},

    {TIANHU, {"tianhu", "天胡", 32}},
    {DIHU, {"dihu", "地胡", 32}},

    {QUANDAIWU, {"quandaiwu", "全带五", 32}},
    {LONGQIDUI, {"longqidui", "龙七对", 32}},
    {SHOUZHONGBAOYI, {"shouzhongbaoyi", "守中抱一", 24}},
    {LVYISE, {"lvyise", "绿一色", 24}},
    {SIJIEGAO, {"sijiegao", "四节高", 16}},
    {DAIYAOJIU, {"daiyaojiu", "带幺九", 16}},
    {SHIERJINCHAI, {"shierjinchai", "十二金钗", 12}},
    {JIANGDUI, {"jiangdui", "将对", 16}},
    {QIDUI, {"qidui", "七对", 12}},
    {SANANKE, {"sananke", "三暗刻", 8}},

    {BAIWANDAN, {"baiwandan", "百万石", 8}},
    {QUANSHUANGKE, {"quanshuangke", "全双刻", 8}},
    {SANJIEGAO, {"sanjiegao", "三节高", 8}},
    {JINGOUDIAO, {"jingoudiao", "金钩钓", 8}},
    {DAYUWU, {"dayuwu", "大于五", 8}},
    {XIAOYUWU, {"xiaoyuwu", "小于五", 8}},

    {YITIAOLONG, {"yitiaolong", "一条龙", 6}},
    {QINGYISE, {"qingyise", "清一色", 4}},
    {BUQIUREN, {"buqiuren", "不求人", 2}},
    {SHUANGANKE, {"shuanganke", "双暗刻", 4}},
    {ZHUOWUKUI, {"zhuowukui", "捉五魁", 4}},

    {SHUANGTONGKE, {"shuangtongke", "双同刻", 2}},
    {SUHU, {"suhu", "素胡", 2}},
    {LAOSHAOPEI, {"laoshaopei", "老少配", 2}},
    {PENGPENGHU, {"pengpenghu", "碰碰胡", 2}},
    {DUANYAOJIU, {"duanyaojiu", "断幺九", 2}},
    {DANDIAO, {"dandiao", "单钓", 2}},
    {YIBANGAO, {"yibangao", "一般高", 2}},
    {LIULIANSHUN, {"liulianshun", "六连顺", 2}},
    {MENQING, {"menqing", "门清", 2}},
    {BIANZHANG, {"bianzhang", "边张", 2}},
    {JUEZHANG, {"juezhang", "绝张", 2}},
    {KANZHANG, {"kanzhang", "坎张", 2}},

    {GANGSHANGKAIHUA, {"gangshangkaihua", "杠上开花", 2}},
    {GANGSHANGPAO, {"gangshangpao", "杠上炮", 2}},
    {QIANGGANGHU, {"qiangganghu", "抢杠胡", 2}},
    {HAIDILAOYUE, {"haidilaoyue", "海底捞月", 2}},
    {MIAOSHOUHUICHUN, {"miaoshouhuichun", "妙手回春", 2}},

    {HUJIAOZHUANYI, {"hujiaozhuanyi", "呼叫转移", 0}},
    {GEN, {"gen", "根", 0}},

    {PINGHU, {"pinghu", "平胡", 1}}
};

const unordered_map<MJ_FANXING, vector<MJ_FANXING>> fanPatternRelationMatrix {
    {SANLONGQIDUI, {
        QUANYAOJIU, LVYISE, DAIYAOJIU, BAIWANDAN, DAYUWU, 
        XIAOYUWU, QINGYISE, SUHU, DUANYAOJIU, JUEZHANG
    }},
    {SHIBALUOHAN, {
        QUANYAOJIU, SIANKE, LVYISE, SIJIEGAO, DAIYAOJIU, 
        JIANGDUI, SANANKE, BAIWANDAN, QUANSHUANGKE, SANJIEGAO,
        DAYUWU, XIAOYUWU, QINGYISE, BUQIUREN, SHUANGANKE, 
        SHUANGTONGKE, SUHU, DUANYAOJIU, MENQING
    }},
    {YISESHUANGLONGHUI, {
        SUHU, DANDIAO, BIANZHANG, KANZHANG, JUEZHANG
    }},
    {QUANYAOJIU, {
        SHUANGLONGQIDUI, SIANKE, LONGQIDUI, SHIERJINCHAI, 
        SANANKE, BUQIUREN, SHUANGANKE, SUHU, PENGPENGHU,
        DANDIAO, MENQING
    }},
    {LIANQIDUI, {
        SUHU, DUANYAOJIU
    }},
    {SHUANGLONGQIDUI, {
        LVYISE, BAIWANDAN, DAYUWU, XIAOYUWU, QINGYISE, 
        SUHU, DUANYAOJIU
    }},
    {JIULIANBAODENG, {
        YITIAOLONG, SHUANGANKE, SUHU, DANDIAO, BIANZHANG, 
        KANZHANG, JUEZHANG
    }},
    {SIANKE, {
        LVYISE, SIJIEGAO, DAIYAOJIU, JIANGDUI, SHIERJINCHAI, 
        BAIWANDAN, QUANSHUANGKE, SANJIEGAO,
        DAYUWU, XIAOYUWU, QINGYISE, SHUANGTONGKE, 
        SUHU, DUANYAOJIU, DANDIAO
    }},
    {QUANDAIWU, {
        QINGYISE, BUQIUREN, SHUANGANKE, ZHUOWUKUI, 
        SHUANGTONGKE, SUHU, DANDIAO, YIBANGAO, 
        MENQING, KANZHANG, JUEZHANG
    }},
    {LONGQIDUI, {
        QINGYISE, SUHU, DUANYAOJIU
    }},
    {SHOUZHONGBAOYI, {
        SIJIEGAO, SHIERJINCHAI, JIANGDUI, SANANKE, 
        BAIWANDAN, QUANSHUANGKE, SANJIEGAO,
        DAYUWU, XIAOYUWU, QINGYISE, BUQIUREN, 
        SHUANGANKE, SHUANGTONGKE, MENQING
    }},
    {LVYISE, {
        SHIERJINCHAI, SANANKE, QUANSHUANGKE, SANJIEGAO, 
        JINGOUDIAO, XIAOYUWU, BUQIUREN, SHUANGANKE, SUHU,
        PENGPENGHU, KANZHANG, JUEZHANG, MENQING
    }},
    {SIJIEGAO, {
        SHIERJINCHAI, SANANKE, BAIWANDAN, JINGOUDIAO, 
        DAYUWU, XIAOYUWU, QINGYISE, BUQIUREN, SHUANGANKE,
        SHUANGTONGKE, SUHU, DUANYAOJIU, DANDIAO, JUEZHANG, MENQING
    }},
    {DAIYAOJIU, {
        SHIERJINCHAI, SANANKE, XIAOYUWU, DAYUWU, QINGYISE, 
        BUQIUREN, SHUANGANKE, SHUANGTONGKE, SUHU, LAOSHAOPEI,
        PENGPENGHU, DANDIAO, YIBANGAO, MENQING, BIANZHANG, 
        KANZHANG, JUEZHANG
    }},
    {SHIERJINCHAI, {
        JIANGDUI, SANANKE, BAIWANDAN, QUANSHUANGKE, SANJIEGAO, 
        JINGOUDIAO, DAYUWU, XIAOYUWU, QINGYISE,
        BUQIUREN, SHUANGANKE, ZHUOWUKUI, SHUANGTONGKE, 
        SUHU, PENGPENGHU, DUANYAOJIU, DANDIAO, MENQING,
        BIANZHANG, KANZHANG, JUEZHANG
    }},
    {JIANGDUI, {
        SANANKE, QUANSHUANGKE, JINGOUDIAO, QINGYISE, 
        BUQIUREN, SHUANGANKE, SHUANGTONGKE, SUHU, DANDIAO, MENQING
    }},
    {SANANKE, {
        BAIWANDAN, QUANSHUANGKE, SANJIEGAO, JINGOUDIAO, 
        DAYUWU, XIAOYUWU, QINGYISE, BUQIUREN,
        ZHUOWUKUI, SHUANGTONGKE, SUHU, PENGPENGHU, 
        DUANYAOJIU, DANDIAO, MENQING, BIANZHANG, KANZHANG,
        JUEZHANG
    }},
    {QIDUI, {
        QINGYISE, SUHU, DUANYAOJIU
    }},
    {BAIWANDAN, {
        SANJIEGAO, JINGOUDIAO, DAYUWU, QINGYISE, 
        BUQIUREN, SHUANGANKE, ZHUOWUKUI, SHUANGTONGKE, SUHU, PENGPENGHU,
        DUANYAOJIU, DANDIAO, YIBANGAO, LIULIANSHUN, 
        MENQING, BIANZHANG, KANZHANG, JUEZHANG
    }},
    {QUANSHUANGKE, {
        JINGOUDIAO, DAYUWU, XIAOYUWU, QINGYISE, BUQIUREN, 
        SHUANGANKE, SHUANGTONGKE, SUHU, DANDIAO, MENQING
    }},
    {SANJIEGAO, {
        JINGOUDIAO, DAYUWU, XIAOYUWU, QINGYISE, BUQIUREN, 
        SHUANGANKE, ZHUOWUKUI, SHUANGTONGKE, SUHU, PENGPENGHU,
        DUANYAOJIU, DANDIAO, MENQING, BIANZHANG, KANZHANG, JUEZHANG
    }},
    {JINGOUDIAO, {
        DAYUWU, XIAOYUWU, QINGYISE, SHUANGANKE, SHUANGTONGKE, SUHU, DUANYAOJIU
    }},
    {XIAOYUWU, {
        QINGYISE, BUQIUREN, SHUANGANKE, SHUANGTONGKE, SUHU, 
        PENGPENGHU, DUANYAOJIU, DANDIAO, YIBANGAO,
        MENQING, BIANZHANG, KANZHANG, JUEZHANG
    }},
    {DAYUWU, {
        QINGYISE, BUQIUREN, SHUANGANKE, SHUANGTONGKE, SUHU, 
        PENGPENGHU, DUANYAOJIU, DANDIAO, YIBANGAO,
        MENQING, BIANZHANG, KANZHANG, JUEZHANG
    }},
    {YITIAOLONG, {
        QINGYISE, BUQIUREN, ZHUOWUKUI, SUHU, DANDIAO, 
        MENQING, BIANZHANG, KANZHANG, JUEZHANG
    }},
    {QINGYISE, {
        BUQIUREN, SHUANGANKE, ZHUOWUKUI, SHUANGTONGKE, SUHU, 
        LAOSHAOPEI, PENGPENGHU, DUANYAOJIU, DANDIAO, YIBANGAO,
        LIULIANSHUN, MENQING, BIANZHANG, KANZHANG, JUEZHANG
    }},
    {BUQIUREN, {
        SHUANGANKE, ZHUOWUKUI, SHUANGTONGKE, SUHU, LAOSHAOPEI, 
        PENGPENGHU, DUANYAOJIU, DANDIAO, YIBANGAO,
        LIULIANSHUN, MENQING, BIANZHANG, KANZHANG, JUEZHANG
    }},
    {SHUANGANKE, {
        ZHUOWUKUI, SHUANGTONGKE, SUHU, LAOSHAOPEI, 
        PENGPENGHU, DUANYAOJIU, DANDIAO, YIBANGAO,
        LIULIANSHUN, MENQING, BIANZHANG, KANZHANG, JUEZHANG
    }},
    {ZHUOWUKUI, {
        SHUANGTONGKE, SUHU, LAOSHAOPEI, DUANYAOJIU, 
        YIBANGAO, LIULIANSHUN, MENQING, JUEZHANG
    }},
    {SHUANGTONGKE, {
        SUHU, LAOSHAOPEI, PENGPENGHU, DUANYAOJIU, DANDIAO, 
        YIBANGAO, LIULIANSHUN, MENQING, BIANZHANG, KANZHANG,
        JUEZHANG
    }},
    {SUHU, {
        LAOSHAOPEI, PENGPENGHU, DUANYAOJIU, DANDIAO, 
        YIBANGAO, LIULIANSHUN, MENQING,
        BIANZHANG, KANZHANG, JUEZHANG
    }},
    {LAOSHAOPEI, {
        DANDIAO, YIBANGAO, LIULIANSHUN, MENQING, 
        BIANZHANG, KANZHANG, JUEZHANG
    }},
    {PENGPENGHU, {
        DUANYAOJIU, DANDIAO, MENQING
    }},
    {DUANYAOJIU, {
        DANDIAO, YIBANGAO, LIULIANSHUN, MENQING, KANZHANG, JUEZHANG
    }},
    {DANDIAO, {
        YIBANGAO, LIULIANSHUN, MENQING, BIANZHANG, KANZHANG, JUEZHANG
    }},
    {YIBANGAO, {
        LIULIANSHUN, MENQING, BIANZHANG, KANZHANG, JUEZHANG
    }},
    {LIULIANSHUN, {
        MENQING, BIANZHANG, KANZHANG, JUEZHANG
    }},
    {MENQING, {
        BIANZHANG, KANZHANG, JUEZHANG
    }},
    {BIANZHANG, {JUEZHANG}},
    {KANZHANG, {JUEZHANG}},
    {JUEZHANG, {}}
};


const vector<MJ_FANXING> order_fan {
    SANLONGQIDUI, SHIBALUOHAN, YISESHUANGLONGHUI, 
    QUANYAOJIU, LIANQIDUI, SHUANGLONGQIDUI,
    JIULIANBAODENG, SIANKE, QUANDAIWU, LONGQIDUI, 
    SHOUZHONGBAOYI, LVYISE, SIJIEGAO, DAIYAOJIU, SHIERJINCHAI,
    JIANGDUI, QIDUI, SANANKE, BAIWANDAN, QUANSHUANGKE, 
    SANJIEGAO, JINGOUDIAO, XIAOYUWU, DAYUWU, YITIAOLONG,
    QINGYISE, BUQIUREN, SHUANGANKE, ZHUOWUKUI, SHUANGTONGKE, 
    SUHU, LAOSHAOPEI, PENGPENGHU, DUANYAOJIU, DANDIAO,
    YIBANGAO, LIULIANSHUN, MENQING, BIANZHANG, KANZHANG, JUEZHANG
};

const unordered_map<MJ_FANXING, FX_FUNC> fxFuncMap {
    {JUEZHANG,         fx_JueZhang},
    {BIANZHANG,        fx_Bian},
    {KANZHANG,         fx_Kan},
    {QINGYISE,         fx_QingYiSe},
    {PENGPENGHU,       fx_PengPengHu},
    {JINGOUDIAO,       fx_JinGouDiao},
    {SHIBALUOHAN,      fx_ShiBaLuoHan},
    {QIDUI,            fx_QiDui},
    {QUANYAOJIU,       fx_QuanYaoJiu},
    {DAIYAOJIU,        fx_DaiYaoJiu},
    {DUANYAOJIU,       fx_DuanYaoJiu},
    {JIANGDUI,         fx_JiangDui},
    {LAOSHAOPEI,       fx_LaoShaoPei},
    {YITIAOLONG,       fx_YiTiaoLong},
    {DAYUWU,           fx_DaYuWu},
    {XIAOYUWU,         fx_XiaoYuWu},
    {QUANSHUANGKE,     fx_QuanShuangKe},
    {SANJIEGAO,        fx_SanJieGao},
    {SHIERJINCHAI,     fx_ShiErJinChai},
    {SIJIEGAO,         fx_SiJieGao},
    {QUANDAIWU,        fx_QuanDaiWu},
    {LVYISE,           fx_LvYiSe},
    {JIULIANBAODENG,   fx_JiuLianBaoDeng},
    {YISESHUANGLONGHUI,fx_YiSeShuangLongHui},
    {LIANQIDUI,        fx_LianQiDui},
    {ZHUOWUKUI,        fx_ZhuoWuKui},
    {DANDIAO,          fx_DanDiao},
    {BAIWANDAN,        fx_BaiWanDan},
    {LIULIANSHUN,      fx_LianLiu},
    {YIBANGAO,         fx_YiBanGao},
    {SHOUZHONGBAOYI,   fx_DanDiaoHz},
    {SIANKE,           fx_SiAnKe},
    {SANANKE,          fx_SanAnKe},
    {SHUANGANKE,       fx_ShuangAnKe},
    {SHUANGTONGKE,     fx_ShuangTongKe}
};

const unordered_map<MJ_FANXING, RM_FUNC> fxRmFuncMap {
    {ZHUOWUKUI,   rm_WuKui},
    {LAOSHAOPEI,  rm_LaoShao},
    {YIBANGAO,    rm_YiBanGao},
    {LIULIANSHUN, rm_LianLiu},
    {DANDIAO,     rm_DanDiao}
};
